
package com.leo.Testgson_javabean;

import com.google.gson.Gson;


import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class Testgson_javabeanActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Contacter user1 = new Contacter();
        
        user1.setName("jiangxiaolong");
        user1.setPhonenumber("12345678901");
        user1.setTelnumber("12345678");
        user1.setEmail("jiangxiaolong@MQ.com");
        
        Gson gson=new Gson();
        String str = gson.toJson(user1,Contacter.class);
        
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
        
        String str2 = "{'name':'wawa','phonenumber':'1111111111','telnumber':'222222222','email':'wawa@MQ.com'}";
        
        Contacter user2 = gson.fromJson(str2, Contacter.class);
        Toast.makeText(this, user2.getName(), Toast.LENGTH_SHORT).show();
        Toast.makeText(this, user2.getPhonenumber(), Toast.LENGTH_SHORT).show();
        Toast.makeText(this, user2.getTelnumber(), Toast.LENGTH_SHORT).show();
        Toast.makeText(this, user2.getEmail(), Toast.LENGTH_SHORT).show();
        
    }
}